const qs = require('qs');
const axios = require('axios');

let cookie = 't=fcc4fa9b0963dda862830c6c73ca58c8; account-path-guide-s1=true; 52086065_yxjh-filter-1=true; undefined_yxjh-filter-1=true; v=0; cookie2=1a411bdbf1826bdfc3fcbe1b340492fd; _tb_token_=71b76b5a6b13d; alimamapwag=TW96aWxsYS81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTBfMTJfNikgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzYxLjAuMzE2My4xMDAgU2FmYXJpLzUzNy4zNg%3D%3D; cookie32=12fc205f9c5ceabe9959fa7d26a2c8d9; alimamapw=TwtQEFFXWQsGUVcHAQYFCGhUAgYBUlkBAAlRUFYLAFFUAAJXAFEGBgkBBl8HVAVXUA%3D%3D; cookie31=MTIwOTI2NjQzLHhpZXRpYW4yNTQ2NTM0NzgsMzcyNzUxOTk4QHFxLmNvbSxUQg%3D%3D; login=Vq8l%2BKCLz3%2F65A%3D%3D; 120926643_yxjh-filter-1=true; cna=xD5EEr2eKBICAXHco1Rrh1oH; apush602ebc67dbc2a242dbba2f5f24bc1b7b=%7B%22ts%22%3A1507805945561%2C%22parentId%22%3A1507805845385%7D; isg=AlhY-z8lteSEb5l3MReN1LVVKYDgS7ZpOKjND5JNmRNJLfUXNFWpWpDLA1Ln'

let instance = axios.create({
    headers: {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36',
        'Cookie': cookie
    }
});

// let itemId = '547985308669';
// let apply = function (com, cookie) {
//     return instance.post('http://pub.alimama.com/pubauc/applyForCommonCampaign.json', qs.stringify({
//         campId: com.CampaignID,
//         keeperid: com.ShopKeeperID,
//         applyreason: '微信推广',
//         _tb_token_: cookie.match("_tb_token_\=(.*?);")[1]
//     })).then(function (response) {
//         console.log(com.CampaignID, response.data);
//     });
// }
//
// instance.get('http://pub.alimama.com/pubauc/getCommonCampaignByItemId.json?itemId=' + itemId).then(function (response) {
//     let list = response.data && response.data.data;
//     console.log(list);
//
//     let max = null;
//     if (list && list.length) {
//         for (let i in list) {
//             let item = list[i];
//             if (!item.manualAudit) {
//                 if (!max || max.commissionRate < item.commissionRate) {
//                     max = item;
//                 }
//             }
//         }
//     }
//     if (max) {
//         apply(max, cookie);
//     }
// });

// return instance.get('https://pub.alimama.com/common/adzone/newSelfAdzone2.json?tag=29').then(function (response) {
//     console.log(response.data.data.otherAdzones);
// });

// return instance.post('https://pub.alimama.com/common/adzone/selfAdzoneCreate.json', qs.stringify({
//     tag: 29,
//     gcid: 8,
//     siteid: '21192652',
//     selectact: 'add',
//     newadzonename: 'li002',
//     t: new Date().getTime(),
//     _tb_token_: cookie.match("_tb_token_\=(.*?);")[1]
// })).then(function (response) {
//     console.log(response.data);
// });